var commonUtil = require("../../../utils/commonUtil.js")
var globalData = getApp().globalData;
var httpsUrl = globalData.httpsUrl;
var imgUrl = globalData.imgUrl;
var model = require('../../../model/model.js')
var show = false;
var item = {};
Page({

  data: {
    imgUrl: imgUrl,
    item: {
      show: show
    },
  },
  save: function (e) {
    var frm = e.detail.value;//form内容
    frm.province = this.data.province;
    frm.city = this.data.city;
    frm.county = this.data.county;
    console.log("参数：" + JSON.stringify(frm));
    let openId = wx.getStorageSync("openidKey");
    wx.showLoading({title: '请稍等...'})
    wx.request({
      header: { "openId": openId,},
      url: httpsUrl + "/car/regist",
      dataType: "json",
      method: "POST",
      data: frm,
      success: function (res) {
        wx.hideLoading();
        res = res.data;
        console.log("返回：" + JSON.stringify(res));
        if (res.code == 0) {
          wx.navigateBack({
            delta:1
          })
        } else {
          commonUtil.showModal(res.message);
        }
      }
    })
  },
  //点击选择城市按钮显示picker-view
  translate: function (e) {
    model.animationEvents(this, 0, true, 400);
  },
  //隐藏picker-view
  hiddenFloatView: function (e) {
    model.animationEvents(this, 200, false, 400);
  },
  //滑动事件
  bindChange: function (e) {
    model.updateAreaData(this, 1, e);
    item = this.data.item;
    this.setData({
      province: item.provinces[item.value[0]].name,
      city: item.citys[item.value[1]].name,
      county: item.countys[item.value[2]].name
    });
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function (e) {
    var that = this;
    //请求数据
    model.updateAreaData(that, 0, e);
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})